package com.ruoyi.web.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Report;
import com.ruoyi.system.service.IReportService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 举报Controller
 *
 * @author ruoyi
 * @date 2022-07-01
 */
@Api("用户管理")
@Controller
@RequestMapping("/system/report")
public class ReportController extends BaseController {
    private String prefix = "system/report";

    @Autowired
    private IReportService reportService;

    //    @RequiresPermissions("system:report:view")
    @GetMapping()
    public String report() {
        return prefix + "/report";
    }

    /**
     * 查询举报列表
     */
//    @RequiresPermissions("system:report:list")
    @ApiOperation("查询举报列表")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Report report) {
        startPage();
        List<Report> list = reportService.selectReportList(report);
        return getDataTable(list);
    }

    /**
     * 导出举报列表
     */
//    @RequiresPermissions("system:report:export")
    @Log(title = "举报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Report report) {
        List<Report> list = reportService.selectReportList(report);
        ExcelUtil<Report> util = new ExcelUtil<Report>(Report.class);
        return util.exportExcel(list, "举报数据");
    }

    /**
     * 新增举报
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存举报
     */
//    @RequiresPermissions("system:report:add")
    @ApiOperation("新增举报表")
    @Log(title = "举报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Report report) {
        return toAjax(reportService.insertReport(report));
    }

    /**
     * 修改举报
     */
//    @RequiresPermissions("system:report:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Report report = reportService.selectReportById(id);
        mmap.put("report", report);
        return prefix + "/edit";
    }

    /**
     * 修改保存举报
     */
//    @RequiresPermissions("system:report:edit")
    @ApiOperation("修改保存举报")
    @Log(title = "举报", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Report report) {
        return toAjax(reportService.updateReport(report));
    }

    /**
     * 删除举报
     */
//    @RequiresPermissions("system:report:remove")
    @ApiOperation("删除举报")
    @Log(title = "举报", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(reportService.deleteReportByIds(ids));
    }

    /**
     * 自己的新增举报
     *
     * @param report
     * @return
     */
    @PostMapping("/myadd")
    @ResponseBody
    public AjaxResult myadd(Report report) {
        return toAjax(reportService.insertReport(report));
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @PostMapping("/myremove")
    @ResponseBody
    public AjaxResult myremove(
            @RequestParam("id") Long id
    ) {
        return toAjax(reportService.deleteReportById(id));
    }

/**
 * 可能需要重新设计，因为要考虑举报状态
 */
}
